-- petrifaction
-- created by xinj
-- 石化

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    
    -- 每回合触发
    trigger = function(who, prop, base)
        local force = prop[3];

        -- 不能为负
        force = math.max(0, force);

        return math.modf(base * force / 1000);
    end,

    clear = function (target, prop)
        -- 只对怪物起作用
        if target.type == OBJECT_TYPE_MONSTER then
            local pos = target:getOwner();

            -- 怪物清除了“石化凝视”事件
            EventMgr.fire(event.GRID_LOCK_STATE, {["pos"] = pos, });

            -- 当前石化属性被清除了
            if #PropM.fetchProps(target, "petrifaction") <= 0 then
                -- 抛出事件显示待机动画
                EventMgr.fire(event.GRID_PLAY_ACTION, {["pos"] = pos, });
                -- 抛出事件结束石化效果
                EventMgr.fire(event.GRID_STOP_STONE, {["pos"] = pos, });
                -- 消除
                target.dbase:delete("isPause");
            end
        end
    end,

    record = function (target, prop, path)
        -- 只对怪物起作用
        if target.type == OBJECT_TYPE_MONSTER then
            -- 打上标记
            target.dbase:set("isPause", true);

            -- 抛出事件播放石化凝固
            local pos = target:getOwner();
            EventMgr.fire(event.GRID_PLAY_STONE, {["pos"] = pos, });
        end
        return false;
    end
};